package Day02;

import java.util.Arrays;
import java.util.Comparator;

public class Test01 {
    public static void main(String[] args) {
        Student[] students = new Student[5];
        students[0] = Student.builder().name("张三").age(18).score(90).build();
        students[1] = Student.builder().name("李四").age(19).score(80).build();
        students[2] = Student.builder().name("王五").age(20).score(70).build();
        students[3] = Student.builder().name("赵六").age(21).score(60).build();
        students[4] = Student.builder().name("孙七").age(22).score(50).build();
        System.out.println("按照成绩升序排序：");
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getScore() - o2.getScore();
            }
        });
        for (Student student : students) {
            System.out.println(student);
        }
        System.out.println("按照年龄升序排序：");
        Arrays.sort(students);
        for (Student student : students) {
            System.out.println(student);
        }
    }
}
